/**
 * java多线程模式
 * @author andy.rong
 */

package com.myjavalab.thread;

public class TalkThread extends Thread{
	private RequestQueue inQueue;
	private RequestQueue outQueue;
	public TalkThread(RequestQueue inQueue, RequestQueue outQueue, String name) {
		super(name);
		this.inQueue = inQueue;
		this.outQueue = outQueue;
	}
	
	public void run() {
		System.out.println(Thread.currentThread().getName() + ":Begin");
		for(int i = 0; i < 20; i++) {
			Request r1 = inQueue.getRequest();
			System.out.println(Thread.currentThread().getName() + " gets " + r1);
			Request r2 = new Request(r1.getName() + "!");
			outQueue.putRequest(r2);
			System.out.println(Thread.currentThread().getName() + ":End");

		}
	}
	
	public static void main(String[] args) {
		RequestQueue queue1 = new RequestQueue();
		RequestQueue queue2 = new RequestQueue();
		queue1.putRequest(new Request("request"));
		new TalkThread(queue1, queue2, "Alice").start();
		new TalkThread(queue2, queue1, "Bobby").start();
	}
}
